<template>
  <div class="container">
    <div class="input_modal">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="联系我们" name="1"></el-tab-pane>
        <el-tab-pane label="用户协议" name="2"></el-tab-pane>
        <el-tab-pane label="直播客服" name="3"></el-tab-pane>
        <el-tab-pane label="货物说明" name="4"></el-tab-pane>
      </el-tabs>
    </div>

    <div class="table_con">
      <bg-editor
        :minHeight="300"
        :uploadUrl="uploadUrl"
        :content="detail"
        @editorData='editorInfo'
        v-if="activeName != '3'"
      >
      </bg-editor>
      <div v-else>
        <div class="input-modal">
          <div class="input-item">
            <span>直播客服：</span>
            <el-input
              v-model="detail"
              placeholder="请输入"
              class="proName"
              style="width: 300px;"
            />
          </div>
        </div>
      </div>
      <el-button type="primary" @click="handleSave" style="margin-top: 20px;">保存</el-button>

    </div>
  </div>
</template>

<script>
  let CONSTANT = require("../../constant/constant.js");
  let common = require("../../common.js");
  export default {
    data() {
      return {
        detail: '',
        uploadUrl: '',
        activeName: '1'
      };
    },
    components: {
      "bg-editor": () => import("../common/bg-editor.vue")
    },
    mounted() {
      this.getDetail()
    },
    methods: {
      handleClick(e) {
        this.activeName = e.name;
        this.getDetail()
      },
      editorInfo(e) {
        this.detail = e;
      },
      getDetail: function() {
        let url = '';
        switch(this.activeName) {
          case '1':
            url = CONSTANT.URL.SETTING.contact;
            break;
          case '2':
            url = CONSTANT.URL.SETTING.license;
            break;
          case '3':
            url = CONSTANT.URL.SETTING.live;
            break;
          case '4':
            url = CONSTANT.URL.SETTING.goodNote;
            break;
        }
        common.post(url, null,null, res => {
          this.detail = res.data.bussData;
          $('#summernote').summernote('code', this.detail)
        });
      },
      handleSave() {
        let url = '';
        switch(this.activeName) {
          case '1':
            url = CONSTANT.URL.SETTING.contactSet;
            break;
          case '2':
            url = CONSTANT.URL.SETTING.licenseSet;
            break;
          case '3':
            url = CONSTANT.URL.SETTING.liveSet;
            break;
          case '4':
            url = CONSTANT.URL.SETTING.goodSet;
            break;
        }
        common.post(url, {value: this.detail},null, res => {
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: '保存成功'
            })
          } else {
            this.$message({
              type: 'warning',
              message: res.data.errMsg
            })
          }
        });
      }
    },
    filters: {
      formatStatus(value) {
        var list = [];
        list["y"] = "上架";
        list["n"] = "下架";
        if (value) {
          return list[value];
        } else {
          return "--";
        }
      }
    }
  };
</script>
